package com.example.pufang.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.example.common.CommonResult;
import com.example.common.PageParamRequest;
import com.example.pufang.pojo.Feedback;
import com.example.pufang.service.FeedbackService;
import com.example.pufang.vo.PageListVo;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/feedback")
@CrossOrigin
@Api(tags = "web反馈接口")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @Operation(summary = "获取分页用户列表")
    @GetMapping("getListByPage")
    public CommonResult<PageListVo> getListByPage(PageParamRequest pageParamRequest,
                                                  String searchPhone, String searchName, String searchRealName) {
        return CommonResult.success(feedbackService.getListByPage(pageParamRequest, searchName, searchRealName, searchPhone));
    }

    @Operation(summary = "回复反馈")
    @PostMapping("reply")
    public CommonResult<Boolean> reply(@RequestBody Feedback feedback) {

        if (ObjectUtils.isNull(feedbackService.getById(feedback.getId()))) {
            return CommonResult.failed("找不到该反馈记录");
        }

        return CommonResult.success(feedbackService.reply(feedback));
    }

}
